package com.slipper.sfts.stock.service;

import java.util.List;
import java.util.Map;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;

import com.slipper.sfts.stock.dao.StockDealDao;
import com.slipper.sfts.api.stock.bo.StockDealBO;

import com.slipper.common.transaction.ReadTransactional;
import com.slipper.common.transaction.WriteTransactional;
import com.slipper.common.util.Tool;

@Service
@ReadTransactional
public class StockDealService {
    @Resource
    private StockDealDao stockDealDao;
    
    public StockDealBO queryBy(String id) {
        return stockDealDao.queryBy(id);
    }
    
    public List<StockDealBO> queryList(StockDealBO bo) {
        return stockDealDao.queryList(bo);
    }
    
    public PageInfo<StockDealBO> queryPage(StockDealBO bo) {
        PageHelper.startPage(bo.getPageNumber(), bo.getPageSize());
        return new PageInfo<>(stockDealDao.queryList(bo));
    }
    
    @WriteTransactional
    public int save(StockDealBO bo) {
        if (bo.getId() != null && !"".equals(bo.getId())) {
            return stockDealDao.update(bo);
        } else {
            bo.setId(Tool.getUUID());
            return stockDealDao.insert(bo);
        }
    }
    
    @WriteTransactional
    public int delete(StockDealBO bo) {
        return stockDealDao.delete(bo);
    }

    public PageInfo<Map<String, Object>> queryMemberReportPage(StockDealBO bo) {
        PageHelper.startPage(bo.getPageNumber(), bo.getPageSize());
        return new PageInfo<>(stockDealDao.queryMemberReportList(bo));
    }

    public PageInfo<Map<String, Object>> queryBrokerReportPage(StockDealBO bo) {
        PageHelper.startPage(bo.getPageNumber(), bo.getPageSize());
        return new PageInfo<>(stockDealDao.queryBrokerReportList(bo));
    }

    public PageInfo<Map<String, Object>> queryDateReportPage(StockDealBO bo) {
        PageHelper.startPage(bo.getPageNumber(), bo.getPageSize());
        return new PageInfo<>(stockDealDao.queryDateReportList(bo));
    }
}
